package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueApplyDao;
import com.prs.crm.domain.doc.IssueApply;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Apply;
import com.prs.crm.service.doc.IssueApplyService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.ApplyService;

public class IssueApplyServiceImpl extends BaseServiceImpl<IssueApply,IssueApplyDao> implements IssueApplyService{
	private PersonService personService;
	private ApplyService applyService;
	
	@Override
	public void submitIssueApply(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Apply> applys = this.getApplyService().getApplyByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		
		for(Person person : persons) {
			for(Apply apply : applys) {
				IssueApply issue = new IssueApply();
				issue.setApply(apply);
				issue.setReceivePerson(person);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public ApplyService getApplyService() {
		return applyService;
	}

	public void setApplyService(ApplyService applyService) {
		this.applyService = applyService;
	}

	@Override
	public Collection<IssueApply> getValidIssueApply(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueApply(person);
	}

}
